﻿using LoadClient.YUAN.E;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace LoadClient.YUAN.B
{
    public class ReportManager
    {
        public static List<LoadReport> GetLoadReportList()
        {
            return FreeSqlDB.fsql00.Queryable<LoadReport>().ToList();
        }

        public static List<LoadReport> GetLoadReportListByDate(DateTime st, DateTime et)
        {
            return FreeSqlDB.fsql00.Select<LoadReport>().Where(a => a.InsertTime >= st && a.InsertTime <= et).ToList();
        }

        public static List<LoadReport> GetLoadReportListByKeys(string keys, DateTime st, DateTime et)
        {
            return FreeSqlDB.fsql00.Select<LoadReport>().Where(a => a.ProductName.Contains(keys) && a.InsertTime >= st && a.InsertTime <= et).ToList();
        }

        public static List<LoadReport> GetLoadReportListBySerial(int serial)
        {
            return FreeSqlDB.fsql00.Select<LoadReport>().Where(a => a.ProductSerial == serial).ToList();
        }

        public static LoadReport GetLoadReportBySerial(int serial)
        {
            LoadReport lr = FreeSqlDB.fsql00.Select<LoadReport>().Where(a => a.ProductSerial == serial).First();
            return lr == null ? new LoadReport() : lr;
        }

        public static List<LoadReport> GetLoadReportListByFbarID(int fbarid)
        {
            return FreeSqlDB.fsql00.Select<LoadReport>().Where(a => a.FbarId == fbarid).ToList();
        }

        public static int GetLoadReportMaxSerial()
        {
            return FreeSqlDB.fsql00.Select<LoadReport>().Max(a => a.ProductSerial);
        }

        public static int InsertLoadReport(LoadReport lr)
        {
            return FreeSqlDB.fsql00.Insert(lr).ExecuteAffrows();
        }


        //public static int InsertFbarReport(List<FbarReport> brt)
        //{
        //    return FreeSqlDB.fsql00.Insert(brt).ExecuteAffrows();
        //}


        //public static List<FbarReport> GetFbarReportList(int serial)
        //{
        //    List<FbarReport> list = FreeSqlDB.fsql00.Select<FbarReport>().Where(a => a.SerialNumber == serial).ToList();

        //    List<FbarReport> listreport_distinct = list.GroupBy(a => a.StationNumber).Select(a => a.First()).ToList();

        //    return listreport_distinct.OrderBy(a => a.ReportStart).ToList();
        //}


    }
}
